package org.lightcommons.util;

import java.util.ArrayList;
import java.util.List;

public class ThreadPool {
	private List queue = new ArrayList();
	private List targets = new ArrayList();
	private int maxThreads = 10;
	
	protected boolean isEmpty(){
		return queue.isEmpty();
	}
	
	protected Runnable edqueue(){
		if(!queue.isEmpty()){
			Object o = queue.get(0);
			queue.remove(0);
			return (Runnable) o;
		}
		return null;
	}
	
	public void addTask(Runnable r){
		queue.add(r);
		if(targets.size()<maxThreads){
			TargetThread t = new TargetThread(this);
			targets.add(t);
			t.start();
		}
	}
}
